package com.ft.oa.web.sys;

import com.ft.oa.domain.dto.ApiResult;
import com.ft.oa.domain.sys.SysDept;
import com.ft.oa.domain.sys.SysUser;
import com.ft.oa.service.sys.SysDeptService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 部门接口
 */
@RestController
@RequestMapping("/dept")
public class SysDeptController {

    @Resource
    private SysDeptService sysDeptService;


    /**
     * 新增部门
     * @return
     */
    @PostMapping("/add")
    @PreAuthorize("@ss.havePermission()")
    public ApiResult add(@RequestBody SysDept dept){

        sysDeptService.add(dept);
        return ApiResult.simpleSuccess();
    }

    /**
     * 修改部门
     * @return
     */
    @PostMapping("/edit")
    @PreAuthorize("@ss.havePermission()")
    public ApiResult edit(@RequestBody SysDept dept){

        sysDeptService.edit(dept);
        return ApiResult.simpleSuccess();
    }

    /**
     * 部门添加人员
     * @return
     */
    @PostMapping("/add/users")
    @PreAuthorize("@ss.havePermission()")
    public ApiResult addUsers(@RequestBody SysDept dept){

        sysDeptService.addUsers(dept);
        return ApiResult.simpleSuccess();
    }

    /**
     * 部门移除人员
     * @return
     */
    @PostMapping("/remove/users")
    @PreAuthorize("@ss.havePermission()")
    public ApiResult removeUsers(@RequestBody SysDept dept){

        sysDeptService.removeUsers(dept);
        return ApiResult.simpleSuccess();
    }

    /**
     * 删除部门
     * @return
     */
    @PostMapping("/del/{id}")
    @PreAuthorize("@ss.havePermission()")
    public ApiResult del(@PathVariable Integer id){

        sysDeptService.del(id);
        return ApiResult.simpleSuccess();
    }

    /**
     * 部门树
     * @return
     */
    @GetMapping("/tree")
    @PreAuthorize("@ss.havePermission()")
    public ApiResult tree(){

        List<SysDept> list = sysDeptService.tree();
        return ApiResult.successWithData(list);
    }

    /**
     * 部门人员
     * @return
     */
    @PostMapping("/users")
    public ApiResult users(@RequestBody SysDept sysDept){

        List<SysUser> list = sysDeptService.users(sysDept);
        return ApiResult.successWithData(list);
    }

    /**
     * 部门列表
     * @return
     */
    @GetMapping("/list")
    public ApiResult list(){

        List<SysDept> list = sysDeptService.list();
        return ApiResult.successWithData(list);
    }



}
